package com.sky.mapper;

import com.sky.entity.ShoppingCart;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * 购物车管理实现类
 */
@Mapper
public interface ShoppingCartMapper {
    /**
     * 根据用户id、菜品id、套餐id查询购物车
     * @param shoppingCart
     * @return
     */
    ShoppingCart list(ShoppingCart shoppingCart);

    /**
     * 更新购物车数量
     * @param shoppingCart
     */
    @Update("update shopping_cart set number = #{number} where id = #{id}")
    void updateNumber(ShoppingCart shoppingCart);

    /**
     * 新增购物车
     * @param shoppingCart
     */
    @Insert("insert into shopping_cart(name, image, user_id, dish_id, setmeal_id, dish_flavor, number, amount, create_time) " +
            "values (#{name}, #{image}, #{userId}, #{dishId}, #{setmealId}, #{dishFlavor}, #{number}, #{amount}, #{createTime})")
    void insert(ShoppingCart shoppingCart);
    @Select("select * from shopping_cart where user_id = #{userId}")
    List<ShoppingCart> listOfShoppingCart(ShoppingCart shoppingCart);
    @Delete("delete from shopping_cart where user_id = #{userId}")
    void clean(Long userId);

    /**
     * 删除购物车中的一条数据
     * @param cart
     */
    @Delete("delete from shopping_cart where id = #{id}")
    void deleteOne(ShoppingCart cart);

    void insertBatch(List<ShoppingCart> shoppingCarts);
}
